﻿#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "htry.h"
#include <QDebug>



#pragma execution_character_set("utf-8")

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    setWindowTitle("宝可梦个体值计算器");
    connect(ui->pushButton,&QPushButton::clicked,this,&MainWindow::on_buttonCalc_clicked);
}

MainWindow::~MainWindow()
{
    delete ui;
}

int MainWindow::formin(int strength,double v,int level,int bl){
    double k=1.0;
    if(bl==1)k=1.1;
    else if(bl==2)k=0.9;
    else if(bl==3)v=v-5-level;
    for(int i=0;i<=31;i++)
        if((int)(((strength*2*level+i*level)/100.0+5))*k>=v)
            return i;
    return 0;
}

int MainWindow::formax(int strength,double v,int level,int bl){
    double k=1.0;
    if(bl==1)k=1.1;
    else if(bl==2)k=0.9;
    else if(bl==3)v=v-5-level;
    for(int i=1;i<=32;i++)
        if((int)(((strength*2*level+i*level)/100.0+5))*k>=v+1)
            return i-1;
    return 31;
}

void MainWindow::on_buttonCalc_clicked()
{
    int flag=ui->comboBox->currentIndex();
    double level=ui->Level->text().toDouble();
    double hp=ui->hp->text().toDouble();
    double atk=ui->atk->text().toDouble();
    double def=ui->def->text().toDouble();
    double spa=ui->spa->text().toDouble();
    double spd=ui->spd->text().toDouble();
    double spe=ui->spe->text().toDouble();
    int idx=ui->idx->text().toInt()-1;
    ui->hpv->setText(QString::number(formin(a[idx][0],hp,level,3))+"~"+QString::number(formax(a[idx][0],hp,level,3)));
    ui->atkv->setText(QString::number(formin(a[idx][1],atk,level,b[flag][0]))+"~"+QString::number(formax(a[idx][1],atk,level,b[flag][0])));
    ui->defv->setText(QString::number(formin(a[idx][2],def,level,b[flag][1]))+"~"+QString::number(formax(a[idx][2],def,level,b[flag][1])));
    ui->spav->setText(QString::number(formin(a[idx][3],spa,level,b[flag][2]))+"~"+QString::number(formax(a[idx][3],spa,level,b[flag][2])));
    ui->spdv->setText(QString::number(formin(a[idx][4],spd,level,b[flag][3]))+"~"+QString::number(formax(a[idx][4],spd,level,b[flag][3])));
    ui->spev->setText(QString::number(formin(a[idx][5],spe,level,b[flag][4]))+"~"+QString::number(formax(a[idx][5],spe,level,b[flag][4])));
}


